<?php $this->load->view('_inc/header'); ?>
<script>
$(document).ready(function(){
   $('.cadastrar').click(function(){
           var divEditar = $('.popUp');
           $.ajax({
                url: '<?php echo base_url()?>index.php/turma/cadastrar',
                type: 'POST',
                success: function(data){
                    divEditar.html(data);
                    abrePopUp();
                }
        });
    }); 
    
    $('.editar').click(function(){
           var id = $(this).attr('id');
           var divEditar = $('.popUp');
           $.ajax({
                url: '<?php echo base_url()?>index.php/turma/editar/' + id,
                type: 'POST',
                success: function(data){
                    divEditar.html(data);
                    abrePopUp();
                }
        });
    });
    
    $('.excluir').click(function(){      
        if(confirm("Deseja realmente excluir esta turma?")){
            var id = $(this).attr('id');
            var url = $(this).attr('name');
            $(this).parent('td').parent('tr').css('background','#ff9999').hide(600);
            $.ajax({
                url: '<?php echo base_url()?>index.php/turma/excluir/' + id,
                type: 'POST',
            });
        }
    });
    
});
</script>

<button class="cadastrar" onClick="window.location.href='<?php echo base_url();?>turma/cadastrar'">Nova Turma</button>

<div id="pesquisa">
    <img src="<?php echo base_url()?>public/imagens/icones/pesquisar.png"/>
    <input id="pesquisar">
</div>

<table class="listagem sort">
    <thead>
        <tr>
            <th>Letra</th>
            <th>Disciplina</th>
            <th>Professor</th>
            <th>Horário</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($turmas as $turma) : ?>
        <tr>
            <td><?php echo $turma->letra?></td>
            <td><?php echo $turma->disciplina?></td>
            <td><?php echo $turma->nome?></td>
            <td><?php echo $turma->horario.' - '.$turma->dias?></td>
            <td><?php echo anchor('turma/visualizar/'.$turma->id,' ','class="icone pesquisar" title="Visualizar Membro"');?></td>
            <td><a class="icone editar" id="<?php echo $turma->id?>"></a></td>
            <td><a class="icone excluir notcheck" id="<?php echo $turma->id?>"></a></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php $this->load->view('_inc/footer'); ?>